home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / Hyperion / src / ui_cdinfo.c < prev    next >
C/C++ Source or Header  |  1997-02-26  |  11KB  |  460 lines

  1. /*
  2.  * @(#)ui_cdinfo.c    1.6    5/21/94
  3.  *
  4.  * ui_cdinfo.c - handle the user interface elements in the CD Info popup.
  5.  */
  6. static char *ident = "@(#)ui_cdinfo.c    1.6 5/21/94";
  7.  
  8. #include <stdio.h>
  9. #include <sys/param.h>
  10. #include <sys/types.h>
  11. #include <xview/xview.h>
  12. #include <xview/panel.h>
  13. #include "workman_ui.h"
  14. #include "struct.h"
  15.  
  16. void    continued();
  17. void    setup_itimer();
  18. void    init_stats();
  19. void    avoid_track();
  20. void    keep_settings();
  21. void    cd_volume();
  22. void    set_default_volume();
  23. char *    listentry();
  24. char *    trackname();
  25. int *    get_playlist();
  26. void    kill_stats();
  27. void    insert_into_playlist();
  28. void    scoot_stuff();
  29. int    switch_playlists();
  30.  
  31. extern Panel_item quitbutton;
  32. extern Rect    *track_rect;
  33. extern int    add_height, small_height, basic_spacing;
  34.  
  35. /*
  36.  * Global object definitions.
  37.  */
  38. extern window1_objects    *Workman_window1;
  39. extern popup1_objects    *Workman_popup1;
  40. extern about_objects    *Workman_about;
  41. extern goodies_objects    *Workman_goodies;
  42. extern plpopup_objects    *Workman_plpopup;
  43.  
  44. extern int num_names, num_nalloc, my_cdname, my_artist;
  45. extern int cur_track, cur_pos_abs, cur_pos_rel, cur_tracklen, cur_cdlen,
  46.     cur_ntracks, cur_nsections, cur_lasttrack;
  47. extern enum cd_modes cur_cdmode;
  48. extern int cur_frame;
  49. extern char *cur_cdname, *cur_artist;
  50. extern int displayed_track, pop_track, *pop_list, pop_listsize, pl_item,
  51.     pl_listnum;
  52. extern char *empty;
  53. extern int dont_retry, dismiss_button, info_modified;
  54. extern void (*text_event_handler)();
  55. extern unsigned short speaker_bits[][15];
  56.  
  57. /*
  58.  * Stash the current settings away in memory (in preparation for changing
  59.  * tracks, for instance, or before a save.)
  60.  */
  61. void
  62. keep_settings(ip)
  63.     window1_objects    *ip;
  64. {
  65.     popup1_objects    *pu = Workman_popup1;
  66.  
  67.     stash_cdinfo(xv_get(pu->artist, PANEL_VALUE),
  68.         xv_get(pu->cdname, PANEL_VALUE),
  69.         xv_get(pu->autoplay, PANEL_VALUE),
  70.         xv_get(pu->playmode, PANEL_VALUE), NULL);
  71.     if (pop_track > 0)
  72.         stash_trkinfo(pop_track, xv_get(pu->trackname, PANEL_VALUE),
  73.             xv_get(pu->trackoptions, PANEL_VALUE) & 1,
  74.             xv_get(pu->trackoptions, PANEL_VALUE) & 2);
  75. }
  76.  
  77. /*
  78.  * Callback function for Apply button.
  79.  */
  80. void
  81. save_config(item, event)
  82.     Panel_item    item;
  83.     Event        *event;
  84. {
  85.     keep_settings(Workman_window1);
  86.     save();
  87.     info_modified = 0;
  88. }
  89.  
  90. /*
  91.  * Notify callback function for `delete'.
  92.  */
  93. void
  94. delete_from_playlist(item, event)
  95.     Panel_item    item;
  96.     Event        *event;
  97. {
  98.     plpopup_objects *ip = Workman_plpopup;
  99.     int i;
  100.     
  101.     info_modified = 1;
  102.  
  103.     if (pl_item >= 0)
  104.     {
  105.         xv_set(ip->playlist, PANEL_LIST_SELECT, pl_item, FALSE,
  106.             PANEL_LIST_DELETE, pl_item, NULL);
  107.         for (i = pl_item; i < pop_listsize; i++)
  108.             pop_list[i] = pop_list[i + 1];
  109.         if (--pop_listsize)
  110.         {
  111.             if (pl_item == pop_listsize)
  112.                 pl_item--;
  113.             xv_set(ip->playlist, PANEL_LIST_SELECT, pl_item,
  114.                 TRUE, NULL);
  115.             cd->lists[pl_listnum].list = pop_list;
  116.         }
  117.         else
  118.         {
  119.             pl_item = -1;
  120.             xv_set(ip->delete, PANEL_INACTIVE, TRUE, NULL);
  121.             free(pop_list);
  122.             pop_list = NULL;
  123.             cd->lists[pl_listnum].list = pop_list;
  124.         }
  125.     }
  126. }
  127.  
  128. /*
  129.  * Notify callback function for `artist'.
  130.  */
  131. Panel_setting
  132. update_title(item, event)
  133.     Panel_item    item;
  134.     Event        *event;
  135. {
  136.     new_trackname_display(cur_track > 0 ? trackname(cur_track - 1)[0] ?
  137.         trackname(cur_track - 1) : NULL : "",
  138.         cur_track);
  139.  
  140.     if (event == NULL)
  141.         return ((Panel_setting)NULL);
  142.     return panel_text_notify(item, event);
  143. }
  144.  
  145. /*
  146.  * Notify callback function for `tracklist'.
  147.  */
  148. int
  149. update_trackname(item, string, client_data, op, event, row)
  150.     Panel_item    item;
  151.     char        *string;
  152.     Xv_opaque    client_data;
  153.     Panel_list_op    op;
  154.     Event        *event;
  155.     int        row;
  156. {
  157.     popup1_objects *ip = Workman_popup1;
  158.     int    options;
  159.     char    *name;
  160.  
  161.     switch(op) {
  162.     case PANEL_LIST_OP_DESELECT:
  163.     case PANEL_LIST_OP_VALIDATE:
  164.         if (! pop_track)    /* workaround for bug 1090204 */
  165.             break;
  166.         options = xv_get(ip->trackoptions, PANEL_VALUE);
  167.         name = (char *) xv_get(ip->trackname, PANEL_VALUE);
  168.         stash_trkinfo(row + 1, name, options & 1, (options & 2) >> 1);
  169.         xv_set(ip->tracklist, PANEL_LIST_STRING, row, listentry(row),
  170.             NULL);
  171.         if (cur_track - 1 == row)
  172.             new_trackname_display(name, cur_track);
  173.         if (op == PANEL_LIST_OP_DESELECT)
  174.         {
  175.             xv_set(ip->trackname, PANEL_VALUE, empty, NULL);
  176.             pop_track = 0;
  177.         }
  178.         break;
  179.  
  180.     case PANEL_LIST_OP_SELECT:
  181.         xv_set(ip->trackname, PANEL_VALUE, trackname(row), NULL);
  182.         xv_set(ip->trackoptions, PANEL_VALUE, (get_avoid(row) ? 2 : 0) |
  183.             (get_contd(row) ? 1 : 0), NULL);
  184.         pop_track = row + 1;
  185.         if (xv_get(ip->whichvolume, PANEL_VALUE))
  186.         {
  187.             xv_set(ip->defaultvolume, PANEL_VALUE,
  188.                 get_default_volume(row + 1), NULL);
  189.             set_default_volume(ip->defaultvolume,
  190.                 get_default_volume(row + 1), NULL);
  191.         }
  192.         break;
  193.  
  194.     case PANEL_LIST_OP_DELETE:
  195.         break;
  196.     }
  197.  
  198.     return XV_OK;
  199. }
  200.  
  201. /*
  202.  * Notify callback function for `trackname'.
  203.  */
  204. Panel_setting
  205. name_entered(item, event)
  206.     Panel_item    item;
  207.     Event        *event;
  208. {
  209.     popup1_objects *ip = Workman_popup1;
  210.     int    next_track = 0;
  211.     Panel_setting    retval;
  212.     
  213.     switch (event_action(event))
  214.     {
  215.         case '\n':
  216.         case '\r':
  217.         case '\033':
  218.             retval = PANEL_NONE;
  219.             next_track = 1;
  220.             break;
  221.         case '\t':
  222.             retval = PANEL_NEXT;
  223.             break;
  224.         default:
  225.             retval = panel_text_notify(item, event);
  226.     }
  227.  
  228. /* If a track was selected, save the current settings and go to the next. */
  229.     if (pop_track)
  230.     {
  231.         if (next_track)
  232.         {
  233.             next_track = pop_track;
  234.             if (next_track == cur_ntracks)
  235.                 next_track = 0;
  236.             xv_set(ip->tracklist, PANEL_LIST_SELECT, pop_track - 1,
  237.                 FALSE, NULL);
  238.             update_trackname(ip->tracklist, listentry(pop_track -
  239.                 1), NULL, PANEL_LIST_OP_DESELECT, event,
  240.                 pop_track - 1);
  241.             xv_set(ip->tracklist, PANEL_LIST_SELECT, next_track,
  242.                 TRUE, NULL);
  243.             update_trackname(ip->tracklist, listentry(next_track),
  244.                 NULL, PANEL_LIST_OP_SELECT, event, next_track);
  245.         }
  246.         else
  247.             update_trackname(ip->tracklist, listentry(pop_track -
  248.                 1), NULL, PANEL_LIST_OP_VALIDATE, event,
  249.                 pop_track - 1);
  250.     }
  251.  
  252.     return (retval);
  253. }
  254.  
  255. /*
  256.  * Notify callback function for `defaultvolume'.
  257.  */
  258. void
  259. set_default_volume(item, value, event)
  260.     Panel_item    item;
  261.     int        value;
  262.     Event        *event;
  263. {
  264.     popup1_objects *ip = Workman_popup1;
  265.     static int    old_image = -1;
  266.     Xv_opaque    old_serverimage;
  267.     int        max = xv_get(item, PANEL_MAX_VALUE);
  268.     int        new_image;
  269.     static int    old_volume = -1;
  270.  
  271.     /*
  272.      * Make the real volume track the default volume while the user is
  273.      * sliding the default slider.
  274.      */
  275.     if (event != NULL)
  276.     {
  277.         info_modified = 1;
  278.  
  279.         if (event_is_up(event))
  280.         {
  281.             if (old_volume != -1)
  282.                 xv_set(Workman_window1->volume, PANEL_VALUE,
  283.                     old_volume, NULL);
  284.             old_volume = -1;
  285.         }
  286.         else
  287.         {
  288.             if (old_volume == -1)
  289.                 old_volume = xv_get(Workman_window1->volume,
  290.                     PANEL_VALUE);
  291.             if (value)
  292.                 xv_set(Workman_window1->volume, PANEL_VALUE,
  293.                     value - 1, NULL);
  294.         }
  295.         figure_volume(Workman_window1);
  296.     }
  297.  
  298.     /* we want this to look sort of logarithmic */
  299.     if (value)
  300.     {
  301.         default_volume(xv_get(ip->whichvolume, PANEL_VALUE) * pop_track,
  302.             value);
  303.         new_image = value / (max / 8);
  304.         value = (max * max) - ((max - value) * (max - value));
  305.     }
  306.     else
  307.     {
  308.         new_image = -1;
  309.         default_volume(xv_get(ip->whichvolume, PANEL_VALUE) * pop_track,
  310.             0);
  311.     }
  312.  
  313.     /* maybe show a new icon... */
  314.     if (new_image > 7)
  315.         new_image = 7;
  316.     if (old_image > -1)
  317.         old_serverimage = xv_get(ip->defaultspeaker, PANEL_LABEL_IMAGE);
  318.     if (new_image != old_image && new_image > -1)
  319.     {
  320.         xv_set(ip->defaultspeaker, PANEL_LABEL_IMAGE,
  321.             xv_create(XV_NULL, SERVER_IMAGE, SERVER_IMAGE_DEPTH, 1,
  322.             XV_WIDTH, 16, XV_HEIGHT, 15, SERVER_IMAGE_BITS,
  323.             speaker_bits[new_image], NULL), NULL);
  324.         if (old_image > -1)
  325.             xv_destroy(old_serverimage);
  326.         else
  327.         {
  328.             xv_set(ip->nonemsg, XV_SHOW, FALSE, NULL);
  329.             xv_set(ip->defaultspeaker, XV_SHOW, TRUE, NULL);
  330.         }
  331.         old_image = new_image;
  332.     }
  333.     if (new_image != old_image && new_image == -1)
  334.     {
  335.         xv_destroy(old_serverimage);
  336.         xv_set(ip->defaultspeaker, XV_SHOW, FALSE, NULL);
  337.         xv_set(ip->nonemsg, XV_SHOW, TRUE, NULL);
  338.         old_image = -1;
  339.     }
  340. }
  341.  
  342. /*
  343.  * Notify callback function for `whichvolume'.
  344.  */
  345. void
  346. set_which_volume(item, value, event)
  347.     Panel_item    item;
  348.     int        value;
  349.     Event        *event;
  350. {
  351.     popup1_objects *ip = Workman_popup1;
  352.     int    vol;
  353.  
  354.     if (value == 1 && ! pop_track)
  355.     {
  356.         xv_set(item, PANEL_VALUE, 0, NULL);
  357.         value = 0;
  358.     }
  359.  
  360.     xv_set(item, PANEL_DEFAULT_VALUE, (value + 1) % 2, NULL);
  361.     xv_set(ip->defaultvolume, PANEL_VALUE, vol = get_default_volume(value ?
  362.         pop_track : 0), NULL);
  363.     set_default_volume(ip->defaultvolume, vol, NULL);
  364. }
  365.  
  366. /*
  367.  * Event notify procedure for text fields, so the PANEL_NOTIFY_PROC gets
  368.  * called when the user clicks on another field.
  369.  */
  370. void
  371. text_event_p(item, event)
  372.     Panel_item    item;
  373.     Event        *event;
  374. {
  375.     Panel_setting   (*fp)();
  376.     int               e;
  377.     char             *pns;
  378.     Panel_setting     level;
  379.     static Panel_item last_item = (Panel_item)NULL;
  380.  
  381.     e = event_id(event);
  382.  
  383. /* call last_item's PANEL_NOTIFY_PROC if user mouse clicks off it
  384.    but don't do this if PANEL_NOTIFY_PROC already gets triggered via kbd */
  385.     if ( (item != last_item) && (event_action(event) == ACTION_SELECT) &&
  386.         (last_item != (Panel_item)NULL) )
  387.     {
  388.         level = (Panel_setting) xv_get(last_item, PANEL_NOTIFY_LEVEL);
  389.         switch (level)
  390.         {
  391.         case PANEL_NONE:
  392.             break;
  393.         case PANEL_NON_PRINTABLE:
  394.             break;
  395.         case PANEL_SPECIFIED:
  396.             pns = (char *)xv_get(last_item, PANEL_NOTIFY_STRING);
  397.             if ( strchr( pns, (char)e ) != NULL)
  398.                 break;
  399.         case PANEL_ALL:
  400.         default:
  401.             fp = (Panel_setting (*)())
  402.                 xv_get(last_item, PANEL_NOTIFY_PROC);
  403.             (*fp)(last_item, event);
  404.             break;
  405.         }
  406.     }
  407.  
  408.     /* save last item in static var */
  409.     last_item = item;
  410.  
  411.     (text_event_handler)(item, event);
  412. }
  413.  
  414. /*
  415.  * Notify callback function for `buttonpl'.
  416.  */
  417. void
  418. popup1_buttonpl_notify_callback(item, event)
  419.     Panel_item    item;
  420.     Event        *event;
  421. {
  422.     popup1_objects *ip = Workman_popup1;
  423.     
  424.     if (dismiss_button && item == ip->buttonpl ||
  425.         xv_get(Workman_plpopup->plpopup, FRAME_CMD_PUSHPIN_IN) == FALSE)
  426.     {
  427.         xv_set(Workman_plpopup->plpopup, FRAME_CMD_PUSHPIN_IN, TRUE,
  428.             NULL);
  429.         xv_set(Workman_plpopup->plpopup, XV_SHOW, TRUE, NULL);
  430.     }
  431.     else
  432.         xv_set(Workman_plpopup->plpopup, FRAME_CMD_PUSHPIN_IN, FALSE,
  433.             XV_SHOW, FALSE, NULL);
  434.     xv_set(Workman_plpopup->plpopup, XV_KEY_DATA, FRAME_CMD_PUSHPIN_IN,
  435.         FALSE, NULL);
  436. }
  437.  
  438. /*
  439.  * Notify callback function for `button8'.
  440.  */
  441. void
  442. cdinfo_reset(item, event)
  443.     Panel_item    item;
  444.     Event        *event;
  445. {
  446.     enum cd_modes    old_cdmode = cur_cdmode;
  447.     
  448.     kill_stats(Workman_window1);
  449.     wipe_cdinfo();
  450.     load();
  451.     init_stats(Workman_window1);
  452.     show_stats(Workman_window1);
  453.     if (old_cdmode == PAUSED)
  454.     {
  455.         cur_cdmode = PAUSED;
  456.         xv_set(Workman_window1->mode, PANEL_VALUE, PAUSED, NULL);
  457.     }
  458.     info_modified = 0;
  459. }
  460.